var vm = new Vue({
    el: '#app',
    data: {
        q: {//搜索条件
            parentUserId: '',
            userId: '',
            date:''
        },
        showList: true,
        sellerData: {
            columns: ['日期', '商户数', '激活数'],
            rows: []
        },
        chartData: {
            columns: ['日期', '交易额', '采购额'],
            rows: []
        },
        totalSeller: 0,
        totalActivate: 0,
        totalTransaction: 0,
        totalPurchase: 0,
        facilitatorList: [], //服务商
        userDistributionList: [], //代理商

        loading: false,
        options: [],
        remoteList: [],
    },
    mounted() {
        this.facilitatorData()
    },
    methods: {
        facilitatorData: function () {
            var self = this
            self.q.date = self.q.date ? self.dateFormat(new Date(self.q.date)) : ''
            $.ajax({
                type: "POST",
                url: baseURL + "facilitator/facilitator/facilitatorData",
                contentType: "application/json",
                data: JSON.stringify(self.q),
                success: function (r) {
                    if (r.code === 0) {
                        console.log(r)
                        var tempList = r.facilitatorList
                        vm.remoteList = tempList.map(item => {
                            return {value: item.user_id, label: item.team_name};
                        });

                        self.totalSeller = r.totalSeller
                        self.totalActivate = r.totalActivate
                        self.totalTransaction = r.totalTransaction
                        self.totalPurchase = r.totalPurchase
                        r.facilitatorVos.forEach(v => {
                            self.sellerData.rows.push({
                                '日期': v.date,
                                '商户数': v.sellerNum,
                                '激活数': v.activateNum
                            })
                            self.chartData.rows.push({
                                '日期': v.date,
                                '交易额': v.transactionAmount,
                                '采购额': v.purchaseAccount
                            })

                        });
                    }
                }
            });
        },
        search() {
            vm.sellerData.rows = []
            vm.chartData.rows = []
            this.facilitatorData()
        },
        rest() {
            vm.q.parentUserId=''
            vm.q.userId=''
            vm.q.date=''
            vm.sellerData.rows = []
            vm.chartData.rows = []
            this.facilitatorData()
        },
        remoteMethod(query) {
            if (query !== '') {
                vm.loading = true;
                setTimeout(() => {
                    vm.loading = false;
                    vm.options = vm.remoteList.filter(item => {
                        return item.label.indexOf(query) > -1;
                    });
                }, 200);
            } else {
                vm.options = [];
            }
        },
        currentSel(val) {
            $.get(baseURL + "facilitator/facilitator/userDistributionList/" + val, function (r) {
                if (r.code === 0) {
                    vm.userDistributionList = r.userDistributionList;
                }
            });
        },
        /* 格式化日期yyyy-MM-dd HH:mm:ss */
        dateFormat(date) {
            var year = date.getFullYear();
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
            return year + "-" + month + "-" + day;
            // return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
        },
    }
});
